#define F(a,b,c) for(ll a=b;a<=(c);a++)
#define f(a,b,c) for(ll a=b;a>=(c);a--)
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
namespace LDY_NAMESPACE{
    ll n,a[1111111],t,ans,T;
    void THE_REAL_MAIN(){
        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
        cin>>T;
        while(T--){
            ans=0;
            memset(a,0,sizeof a);
            cin>>n;
            F(i,1,n) cin>>t,a[t]++;
            F(i,1,1111000) if(a[i]>1)ans+=(a[i]-1)*i;
            cout<<ans<<endl;
        }

    }
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    LDY_NAMESPACE::THE_REAL_MAIN();
    return 0;
}
